import redis

from core.config.redis_config import RedisBuilder


class RedisClient:
    def __init__(self):
        self.client = RedisBuilder.get_redis_client()
        try:
            response = self.client.ping()
            print("Redis 连接成功:", response)
        except redis.AuthenticationError as e:
            print("Redis 认证失败:", e)
        except redis.ConnectionError as e:
            print("Redis 连接失败:", e)

    def connect(self):
        return self.client

    def disconnect(self):
        self.client.close()

# 创建全局的 RedisClient 变量
global_redis_client = RedisClient()

if __name__ == '__main__':
    r = global_redis_client.connect()
    res = r.ping()
    print("Redis 连接成功:", res)